﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Data;

    public class OrderDAL : BaseDAL
    {
        public DataSet List(int pageIndex, int pageMax, int userid, int isView, int isFinish, int isCancel, DateTime fromDate, DateTime toDate)
        {
            DataSet ds = new DataSet();
            string[] uspParaName = new string[] { "?pageIndex", "?pageMax", "?IsView", "?IsFinish", "?IsCancel", "?FromDate", "?ToDate", "?UserId" };
            object[] uspParaValue = new object[] { pageIndex, pageMax, isView, isFinish, isCancel, fromDate, toDate, userid };
            string uspName = "usp_order_list";

            ds = base.RunProcedure(uspParaName, uspParaValue, uspName);
            return ds;
        }

        public string Cancel(int oi)
        {
            DataSet ds = new DataSet();
            string[] uspParaName = new string[] { "?OrderId" };
            object[] uspParaValue = new object[] { oi };
            string uspName = "usp_order_cancel";

            ds = base.RunProcedure (uspParaName, uspParaValue, uspName);
            return ds.Tables[0].Rows[0][0].ToString();
        }

        public string Finish(int oi)
        {
            DataSet ds = new DataSet();
            string[] uspParaName = new string[] { "?OrderId" };
            object[] uspParaValue = new object[] { oi };
            string uspName = "usp_order_finish";

            ds = base.RunProcedure(uspParaName, uspParaValue, uspName);
            return ds.Tables[0].Rows[0][0].ToString();
        }

        public int Insert(int userid, string customerName, string customerNote, string customerPhone, string customerAddress, string customerEmail)
        {
            DataSet ds = new DataSet();
            string[] uspParaName = new string[] { "?UserId", "?OrderCustomerName", "?CreatedDate", "?OrderCustomerNote", "?OrderCustomerPhone", "?OrderCustomerAddress", "?OrderCustomerEmail" };
            object[] uspParaValue = new object[] { userid, customerName, DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"), customerNote, customerPhone, customerAddress, customerEmail };
            string uspName = "usp_order_insert";

            ds = base.RunProcedure(uspParaName, uspParaValue, uspName);

            return int.Parse(ds.Tables[0].Rows[0][0].ToString());
        }
        public int InsertDetail(int orderId, int productId, int quantity, int price)
        {
            DataSet ds = new DataSet();
            string[] uspParaName = new string[] { "?OrderId", "?ProductId", "?Quantity", "?PriceAtBuy", "?Note" };
            object[] uspParaValue = new object[] { orderId, productId, quantity, price, "" };
            string uspName = "usp_detailorder_insert";

            ds = base.RunProcedure(uspParaName, uspParaValue, uspName);

            return 1;
        }

        public DataSet Select(int orderid)
        {
            DataSet ds = new DataSet();
            string[] uspParaName = new string[] { "?OrderId" };
            object[] uspParaValue = new object[] { orderid };
            string uspName = "usp_order_detail";

            ds = base.RunProcedure(uspParaName, uspParaValue, uspName);
            return ds;
        }
        public DataSet SelectDetail(int orderid)
        {
            DataSet ds = new DataSet();
            string[] uspParaName = new string[] { "?OrderId" };
            object[] uspParaValue = new object[] { orderid };
            string uspName = "usp_orderdetail_detail";

            ds = base.RunProcedure(uspParaName, uspParaValue, uspName);
            return ds;
        }
    }
